﻿#include "TrustMerchantDialog.h"
#include "../../MirGraphics/MLibrary.h"
#include "../../MirSounds/SoundManager.h"
#include "../../Settings.h"
#include "../GameScene.h"
#include "../../Forms/Client.CMain.h"
#include "../../../Shared/ClientPackets.h"
#include "../../MirNetwork/Network.h"
#include "../../Program.h"

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirSounds;
namespace C = ClientPackets;

namespace Client::MirScenes::Dialogs
{

bool TrustMerchantDialog::UserMode = false;
MarketPanelType TrustMerchantDialog::MarketType = static_cast<MarketPanelType>(0);
long long TrustMerchantDialog::SearchTime = 0;
long long TrustMerchantDialog::MarketTime = 0;
UserItem *TrustMerchantDialog::SellItemSlot;
TrustMerchantDialog::AuctionRow *TrustMerchantDialog::Selected;

    TrustMerchantDialog::TrustMerchantDialog()
    {
        setIndex(786);
        setLibrary(Libraries::Title);
        setSort(true);
        setMovable(true);
        Size tempVar(492, 478);
        setSize(&tempVar);

        #pragma region TrustMerchant Buttons

        MarketButton = new MirButton();
        MarketButton->setIndex(789);
        MarketButton->setPressedIndex(788);
        MarketButton->setLibrary(Libraries::Title);
        Point tempVar2(9, 35);
        MarketButton->setLocation(&tempVar2);
        MarketButton->setParent(this);
        MarketButton->Click += [&] (o, e)
        {
            TMerchantDialog(MarketPanelType::Market);
            if (tempCell != nullptr)
            {
                tempCell->setLocked(false);
                SellItemSlot = nullptr;
                tempCell = nullptr;
            }
        };

        ConsignmentButton = new MirButton();
        ConsignmentButton->setIndex(791);
        ConsignmentButton->setPressedIndex(790);
        ConsignmentButton->setLibrary(Libraries::Title);
        Point tempVar3(104, 35);
        ConsignmentButton->setLocation(&tempVar3);
        ConsignmentButton->setParent(this);
        ConsignmentButton->setVisible(true);
        ConsignmentButton->Click += [&] (o, e)
        {
            TMerchantDialog(MarketPanelType::Consign);
        };

        AuctionButton = new MirButton();
        AuctionButton->setIndex(817);
        AuctionButton->setPressedIndex(816);
        AuctionButton->setLibrary(Libraries::Title);
        Point tempVar4(199, 35);
        AuctionButton->setLocation(&tempVar4);
        AuctionButton->setParent(this);
        AuctionButton->setVisible(true);
        AuctionButton->Click += [&] (o, e)
        {
            TMerchantDialog(MarketPanelType::Auction);
        };

        GameShopButton = new MirButton();
        GameShopButton->setIndex(819);
        GameShopButton->setPressedIndex(818);
        GameShopButton->setLibrary(Libraries::Title);
        Point tempVar5(389, 35);
        GameShopButton->setLocation(&tempVar5);
        GameShopButton->setParent(this);
        GameShopButton->setVisible(true);
        GameShopButton->Click += [&] (o, e)
        {
            TMerchantDialog(MarketPanelType::GameShop);
        };

        CloseButton = new MirButton();
        CloseButton->setIndex(360);
        CloseButton->setHoverIndex(361);
        CloseButton->setPressedIndex(362);
        Point tempVar6(465, 3);
        CloseButton->setLocation(&tempVar6);
        CloseButton->setLibrary(Libraries::Prguse2);
        CloseButton->setSound(SoundList::ButtonA);
        CloseButton->setParent(this);
        CloseButton->Click += [&] (o, e)
        {
            Hide();
        };

        #pragma region Page Buttons & Label

        HelpLabel = new MirLabel();
        HelpLabel->setText(consignmentText);
        HelpLabel->setParent(this);
        Size tempVar7(115, 205);
        HelpLabel->setSize(&tempVar7);
        Point tempVar8(8, 237);
        HelpLabel->setLocation(&tempVar8);
        Font tempVar9(Settings::FontName, Settings::FontSize - 1);
        HelpLabel->setFont(&tempVar9);
        HelpLabel->setForeColour(Color::White);
        HelpLabel->setVisible(false);

        BackButton = new MirButton();
        BackButton->setIndex(240);
        BackButton->setHoverIndex(241);
        BackButton->setPressedIndex(242);
        BackButton->setLibrary(Libraries::Prguse2);
        Point tempVar10(251, 419);
        BackButton->setLocation(&tempVar10);
        BackButton->setSound(SoundList::ButtonA);
        BackButton->setParent(this);
        BackButton->Click += [&] (o, e)
        {
            if (Page <= 0)
            {
                return;
            }
    
            Page--;
            UpdateInterface();
        };

        NextButton = new MirButton();
        NextButton->setIndex(243);
        NextButton->setHoverIndex(244);
        NextButton->setPressedIndex(245);
        NextButton->setLibrary(Libraries::Prguse2);
        Point tempVar11(320, 419);
        NextButton->setLocation(&tempVar11);
        NextButton->setSound(SoundList::ButtonA);
        NextButton->setParent(this);
        NextButton->Click += [&] (o, e)
        {
            if (Page >= PageCount - 1)
            {
                return;
            }
            if (Page < (Listings.size() - 1) / 10)
            {
                Page++;
                UpdateInterface();
                return;
            }
    
            C::MarketPage *tempVar12 = new C::MarketPage();
            tempVar12->Page = Page + 1;
            Network::Enqueue(tempVar12);
    

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar12' statement was not added since tempVar12 was passed to a method or constructor. Handle memory management manually.
        };

        PageLabel = new MirLabel();
        Size tempVar13(70, 18);
        PageLabel->setSize(&tempVar13);
        Point tempVar14(260, 419);
        PageLabel->setLocation(&tempVar14);
        PageLabel->setDrawFormat(TextFormatFlags::HorizontalCenter);
        PageLabel->setText("0/0");
        PageLabel->setNotControl(true);
        PageLabel->setParent(this);

        UpButton = new MirButton();
        UpButton->setIndex(197);
        UpButton->setHoverIndex(198);
        UpButton->setPressedIndex(199);
        UpButton->setLibrary(Libraries::Prguse2);
        UpButton->setParent(this);
        Size tempVar15(16, 14);
        UpButton->setSize(&tempVar15);
        Point tempVar16(108, 60);
        UpButton->setLocation(&tempVar16);
        UpButton->setSound(SoundList::ButtonA);
        UpButton->setVisible(true);
        UpButton->Click += [&] (o, e)
        {
            if (Skip <= 0)
            {
                return;
            }
    
            Skip--;
    
    
            UpdatePositionBar();
            DrawFilters(SelectedIndex, SelectedSubIndex);
        };


        DownButton = new MirButton();
        DownButton->setIndex(207);
        DownButton->setHoverIndex(208);
        DownButton->setLibrary(Libraries::Prguse2);
        DownButton->setPressedIndex(209);
        DownButton->setParent(this);
        Size tempVar17(16, 14);
        DownButton->setSize(&tempVar17);
        Point tempVar18(108, 429);
        DownButton->setLocation(&tempVar18);
        DownButton->setSound(SoundList::ButtonA);
        DownButton->setVisible(true);

        DownButton->Click += [&] (o, e)
        {
            if (Skip + MaxLines >= PossibleTotal)
            {
                return;
            }
    
            Skip++;
    
            UpdatePositionBar();
            DrawFilters(SelectedIndex, SelectedSubIndex);
        };

        PositionBar = new MirButton();
        PositionBar->setIndex(205);
        PositionBar->setHoverIndex(206);
        PositionBar->setPressedIndex(206);
        PositionBar->setLibrary(Libraries::Prguse2);
        Point tempVar19(108, 73);
        PositionBar->setLocation(&tempVar19);
        PositionBar->setParent(this);
        PositionBar->setMovable(true);
        PositionBar->setSound(SoundList::None);
        PositionBar->setVisible(false);

        PosX = PositionBar->getLocation()->X;
        PosMinY = UpButton->getLocation()->Y + 13;
        PosMaxY = DownButton->getLocation()->Y - 19;

        PositionBar->OnMoving->addListener("PositionBar_OnMoving", std::bind(&TrustMerchantDialog::PositionBar_OnMoving, this, std::placeholders::_1, std::placeholders::_2));

        #pragma endregion

        #pragma endregion


        SetupFilters();

        #pragma region Market Buttons

        MailButton = new MirButton();
        MailButton->setIndex(437);
        MailButton->setHoverIndex(438);
        MailButton->setPressedIndex(439);
        MailButton->setLibrary(Libraries::Prguse);
        Point tempVar20(350, 448);
        MailButton->setLocation(&tempVar20);
        MailButton->setSound(SoundList::ButtonA);
        MailButton->setParent(this);
        MailButton->Click += [&] (o, e)
        {
            if (Selected == nullptr || CMain::Time < MarketTime)
            {
                return;
            }
    
            std::string message = StringHelper::formatSimple("I am interested in purchasing {0} for {1}.", Selected->Listing->Item->getFriendlyName(), Selected->Listing->Price);
    
            GameScene::Scene->MailComposeLetterDialog->ComposeMail(Selected->Listing->Seller, message);
        };

        RefreshButton = new MirButton();
        RefreshButton->setIndex(663);
        RefreshButton->setHoverIndex(664);
        RefreshButton->setPressedIndex(665);
        RefreshButton->setLibrary(Libraries::Prguse);
        Point tempVar21(320, 448);
        RefreshButton->setLocation(&tempVar21);
        RefreshButton->setSound(SoundList::ButtonA);
        RefreshButton->setParent(this);
        RefreshButton->Click += [&] (o, e)
        {
            if (CMain::Time < SearchTime)
            {
                GameScene::Scene->ChatDialog->ReceiveChat(StringHelper::formatSimple("You can search again after {0} seconds.", std::ceil((SearchTime - CMain::Time) / 1000)), ChatType::System);
                return;
            }
            SearchTime = CMain::Time + Globals::SearchDelay;
            SearchTextBox->setText("");
            C::MarketRefresh tempVar22();
            Network::Enqueue(&tempVar22);
        };

        BuyButton = new MirButton();
        BuyButton->setIndex(703);
        BuyButton->setHoverIndex(704);
        BuyButton->setPressedIndex(705);
        BuyButton->setLibrary(Libraries::Title);
        Point tempVar23(380, 448);
        BuyButton->setLocation(&tempVar23);
        BuyButton->setSound(SoundList::ButtonA);
        BuyButton->setParent(this);
        BuyButton->Click += [&] (o, e)
        {
            if (Selected == nullptr || CMain::Time < MarketTime)
            {
                return;
            }
    
            if (UserMode)
            {
                if (Selected->Listing->ItemType == MarketItemType::Consign)
                {
                    if (Selected->Listing->Seller == "For Sale")
                    {
                        MirMessageBox *box = new MirMessageBox(StringHelper::formatSimple("{0} has not sold, Are you sure you want to get it back?", Selected->Listing->Item->getFriendlyName()), MirMessageBoxButtons::YesNo);
                        box->YesButton->Click += [&] (o1, e2)
                        {
                                MarketTime = CMain::Time + 3000;
                                C::MarketGetBack *tempVar24 = new C::MarketGetBack();
                                tempVar24->AuctionID = Selected->Listing->AuctionID;
                                Network::Enqueue(tempVar24);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar24' statement was not added since tempVar24 was passed to a method or constructor. Handle memory management manually.
                        };
                        box->Show();

            delete box;
                    }
                    else
                    {
                        MarketTime = CMain::Time + 3000;
                        C::MarketGetBack *tempVar25 = new C::MarketGetBack();
                        tempVar25->AuctionID = Selected->Listing->AuctionID;
                        Network::Enqueue(tempVar25);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar25' statement was not added since tempVar25 was passed to a method or constructor. Handle memory management manually.
                    }
                }
                else if (Selected->Listing->ItemType == MarketItemType::Auction)
                {
                    if (Selected->Listing->Seller == "No Bid")
                    {
                        MirMessageBox *box = new MirMessageBox(StringHelper::formatSimple("{0} has not sold, Are you sure you want to get it back?", Selected->Listing->Item->getFriendlyName()), MirMessageBoxButtons::YesNo);
                        box->YesButton->Click += [&] (o1, e2)
                        {
                                MarketTime = CMain::Time + 3000;
                                C::MarketGetBack *tempVar26 = new C::MarketGetBack();
                                tempVar26->AuctionID = Selected->Listing->AuctionID;
                                Network::Enqueue(tempVar26);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar26' statement was not added since tempVar26 was passed to a method or constructor. Handle memory management manually.
                        };
                        box->Show();

            delete box;
                    }
                    else
                    {
                        MarketTime = CMain::Time + 3000;
                        C::MarketGetBack *tempVar27 = new C::MarketGetBack();
                        tempVar27->AuctionID = Selected->Listing->AuctionID;
                        Network::Enqueue(tempVar27);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar27' statement was not added since tempVar27 was passed to a method or constructor. Handle memory management manually.
                    }
                }
            }
            else
            {
                switch (Selected->Listing->ItemType)
                {
                    case MarketItemType::Consign:
                    case MarketItemType::GameShop:
                    {
                            MirMessageBox *box = new MirMessageBox(std::string::Format("Are you sure you want to buy {0} for {1:#,##0} {2}?", Selected->Listing->Item->getFriendlyName(), Selected->Listing->Price, MarketType == MarketPanelType::GameShop ? "Credits" : "Gold"), MirMessageBoxButtons::YesNo);
                            box->YesButton->Click += [&] (o1, e2)
                            {
                                    MarketTime = CMain::Time + 3000;
                                    C::MarketBuy *tempVar28 = new C::MarketBuy();
                                    tempVar28->AuctionID = Selected->Listing->AuctionID;
                                    Network::Enqueue(tempVar28);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar28' statement was not added since tempVar28 was passed to a method or constructor. Handle memory management manually.
                            };
                            box->Show();

            delete box;
                    }
                        break;
                    case MarketItemType::Auction:
                    {
                            MirAmountBox *bidAmount = new MirAmountBox("Bid Amount:", Selected->Listing->Item->Info->Image, std::numeric_limits<unsigned int>::max(), Selected->Listing->Price + 1, Selected->Listing->Price + 1);
    
                            bidAmount->OKButton->Click += [&] (o1, e1)
                            {
                                    MirMessageBox *box = new MirMessageBox(std::string::Format("Are you sure you want to bid {0:#,##0} Gold for {1}?", bidAmount->Amount, Selected->Listing->Item->getFriendlyName()), MirMessageBoxButtons::YesNo);
                                    box->YesButton->Click += [&] (o2, e2)
                                    {
                                        MarketTime = CMain::Time + 3000;
                                        C::MarketBuy *tempVar29 = new C::MarketBuy();
                                        tempVar29->AuctionID = Selected->Listing->AuctionID;
                                        tempVar29->BidPrice = bidAmount->Amount;
                                        Network::Enqueue(tempVar29);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar29' statement was not added since tempVar29 was passed to a method or constructor. Handle memory management manually.
                                    };

                                    box->Show();

            delete box;
                            };
    
                            bidAmount->Show();

            delete bidAmount;
                    }
                        break;
                }
            }
        };

        SellNowButton = new MirButton();
        SellNowButton->setIndex(700);
        SellNowButton->setHoverIndex(701);
        SellNowButton->setPressedIndex(702);
        SellNowButton->setLibrary(Libraries::Title);
        Point tempVar30(324, 448);
        SellNowButton->setLocation(&tempVar30);
        SellNowButton->setSound(SoundList::ButtonA);
        SellNowButton->setParent(this);
        SellNowButton->Click += [&] (o, e)
        {
            if (Selected == nullptr || CMain::Time < MarketTime)
            {
                return;
            }
    
            MarketTime = CMain::Time + 3000;
            C::MarketSellNow *tempVar31 = new C::MarketSellNow();
            tempVar31->AuctionID = Selected->Listing->AuctionID;
            Network::Enqueue(tempVar31);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar31' statement was not added since tempVar31 was passed to a method or constructor. Handle memory management manually.
        };

        #pragma endregion

        #pragma region Search

        SearchTextBox = new MirTextBox();
        Point tempVar32(11, 452);
        SearchTextBox->setLocation(&tempVar32);
        Size tempVar33(110, 18);
        SearchTextBox->setSize(&tempVar33);
        SearchTextBox->setMaxLength(20);
        SearchTextBox->setParent(this);
        SearchTextBox->CanLoseFocus = true;
        SearchTextBox->TextBox->KeyPress += SearchTextBox_KeyPress;
        SearchTextBox->TextBox->KeyUp += SearchTextBox_KeyUp;
        SearchTextBox->TextBox->KeyDown += SearchTextBox_KeyDown;

        FindButton = new MirButton();
        FindButton->setIndex(480);
        FindButton->setHoverIndex(481);
        FindButton->setPressedIndex(482);
        FindButton->setLibrary(Libraries::Title);
        Point tempVar34(124, 448);
        FindButton->setLocation(&tempVar34);
        FindButton->setSound(SoundList::ButtonA);
        FindButton->setParent(this);
        FindButton->Click += [&] (o, e)
        {
            if (SearchTextBox->getText().empty())
            {
                return;
            }
            if (CMain::Time < SearchTime)
            {
                GameScene::Scene->ChatDialog->ReceiveChat(StringHelper::formatSimple("You can search again after {0} seconds.", std::ceil((SearchTime - CMain::Time) / 1000)), ChatType::System);
                return;
            }
    
            SearchTime = CMain::Time + Globals::SearchDelay;
            C::MarketSearch *tempVar35 = new C::MarketSearch();
            tempVar35->Match = SearchTextBox->getText();
            tempVar35->MarketType = MarketType;
            Network::Enqueue(tempVar35);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar35' statement was not added since tempVar35 was passed to a method or constructor. Handle memory management manually.
        };

        #pragma endregion

        #pragma region Gold Label
        TotalGold = new MirLabel();
        Size tempVar36(120, 16);
        TotalGold->setSize(&tempVar36);
        TotalGold->setDrawFormat(TextFormatFlags::HorizontalCenter | TextFormatFlags::VerticalCenter);
        Point tempVar37(6, 451);
        TotalGold->setLocation(&tempVar37);
        TotalGold->setParent(this);
        TotalGold->setNotControl(true);
        Font tempVar38(Settings::FontName, Settings::FontSize);
        TotalGold->setFont(&tempVar38);
        TotalGold->setVisible(false);
        #pragma endregion

        #pragma region ItemCell

        ItemCell = new MirItemCell();
        ItemCell->setBorderColour(Color::Lime);
        ItemCell->setGridType(MirGridType::TrustMerchant);
        ItemCell->setLibrary(Libraries::Items);
        ItemCell->setParent(this);
        Point tempVar39(47, 104);
        ItemCell->setLocation(&tempVar39);
        ItemCell->setItemSlot(0);
        ItemCell->setVisible(false);
        ItemCell->Click += [&] (o, e)
        {
            ItemCell_Click();
        };

        PriceTextBox = new MirTextBox();
        Point tempVar40(15, 165);
        PriceTextBox->setLocation(&tempVar40);
        Size tempVar41(100, 18);
        PriceTextBox->setSize(&tempVar41);
        PriceTextBox->setMaxLength(20);
        PriceTextBox->setParent(this);
        PriceTextBox->CanLoseFocus = true;
        PriceTextBox->setVisible(false);
        PriceTextBox->TextBox->TextChanged += TextBox_TextChanged;
        PriceTextBox->TextBox->KeyPress += MirInputBox_KeyPress;

        SellItemButton = new MirButton();
        SellItemButton->setIndex(700);
        SellItemButton->setPressedIndex(702);
        SellItemButton->setHoverIndex(701);
        SellItemButton->setLibrary(Libraries::Title);
        SellItemButton->setSound(SoundList::ButtonA);
        Point tempVar42(39, 188);
        SellItemButton->setLocation(&tempVar42);
        SellItemButton->setParent(this);
        SellItemButton->setVisible(false);
        SellItemButton->setEnabled(false);
        SellItemButton->Click += [&] (o, e)
        {
            C::ConsignItem *tempVar43 = new C::ConsignItem();
            tempVar43->UniqueID = SellItemSlot->UniqueID;
            tempVar43->Price = Amount;
            tempVar43->Type = MarketType;
            Network::Enqueue(tempVar43);
            SellItemSlot = nullptr;
            PriceTextBox->setText("");
            SellItemButton->setEnabled(false);
            TMerchantDialog(MarketType);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar43' statement was not added since tempVar43 was passed to a method or constructor. Handle memory management manually.
        };


        #pragma endregion

        #pragma region Auction Rows
        for (int i = 0; i < Rows.size(); i++)
        {
            AuctionRow *tempVar44 = new AuctionRow();
            Point tempVar45(127, 82 + i * 33);
            tempVar44->setLocation(&tempVar45);
            tempVar44->setParent(this);
            Rows[i] = tempVar44;
            Rows[i]->Click += [&] (o, e)
            {
                Selected = static_cast<AuctionRow*>(o);
                UpdateInterface();
            };

            delete tempVar44;
        }
        #pragma endregion

        #pragma region Labels

        TitleSalePriceLabel = new MirLabel();
        TitleSalePriceLabel->setText("SALE PRICE");
        TitleSalePriceLabel->setParent(this);
        Font tempVar46(Settings::FontName, Settings::FontSize - 1, FontStyle::Italic);
        TitleSalePriceLabel->setFont(&tempVar46);
        TitleSalePriceLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar47(100, 21);
        TitleSalePriceLabel->setSize(&tempVar47);
        Point tempVar48(15, 142);
        TitleSalePriceLabel->setLocation(&tempVar48);

        TitleSellLabel = new MirLabel();
        TitleSellLabel->setText("SELL ITEM");
        TitleSellLabel->setParent(this);
        Font tempVar49(Settings::FontName, Settings::FontSize - 1, FontStyle::Italic);
        TitleSellLabel->setFont(&tempVar49);
        TitleSellLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar50(110, 21);
        TitleSellLabel->setSize(&tempVar50);
        Point tempVar51(10, 60);
        TitleSellLabel->setLocation(&tempVar51);

        TitleItemLabel = new MirLabel();
        TitleItemLabel->setText("ITEM");
        TitleItemLabel->setParent(this);
        Font tempVar52(Settings::FontName, Settings::FontSize - 1, FontStyle::Italic);
        TitleItemLabel->setFont(&tempVar52);
        TitleItemLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar53(166, 21);
        TitleItemLabel->setSize(&tempVar53);
        Point tempVar54(127, 60);
        TitleItemLabel->setLocation(&tempVar54);

        TitlePriceLabel = new MirLabel();
        TitlePriceLabel->setText("PRICE");
        TitlePriceLabel->setParent(this);
        Font tempVar55(Settings::FontName, Settings::FontSize - 1, FontStyle::Italic);
        TitlePriceLabel->setFont(&tempVar55);
        TitlePriceLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar56(88, 21);
        TitlePriceLabel->setSize(&tempVar56);
        Point tempVar57(295, 60);
        TitlePriceLabel->setLocation(&tempVar57);

        TitleExpiryLabel = new MirLabel();
        TitleExpiryLabel->setText("EXPIRY");
        TitleExpiryLabel->setParent(this);
        Font tempVar58(Settings::FontName, Settings::FontSize - 1, FontStyle::Italic);
        TitleExpiryLabel->setFont(&tempVar58);
        TitleExpiryLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar59(98, 21);
        TitleExpiryLabel->setSize(&tempVar59);
        Point tempVar60(384, 60);
        TitleExpiryLabel->setLocation(&tempVar60);

        #pragma endregion
    }

    void TrustMerchantDialog::SetupFilters()
    {
        auto all = new Filter();
        all->setIndex(0);
        all->setTitle("Show All Items");
        all->setType(std::make_optional(ItemType::Nothing));
        auto weapon = new Filter();
        weapon->setIndex(1);
        weapon->setTitle("Weapon Items");
        weapon->setType(std::make_optional(ItemType::Weapon));
        auto drapery = new Filter();
        drapery->setIndex(2);
        drapery->setTitle("Drapery Items");
        drapery->setType(std::nullopt);
        auto accessory = new Filter();
        accessory->setIndex(3);
        accessory->setTitle("Accessory Items");
        accessory->setType(std::nullopt);
        auto consumable = new Filter();
        consumable->setIndex(4);
        consumable->setTitle("Consumable Items");
        consumable->setType(std::nullopt);
        auto enhancement = new Filter();
        enhancement->setIndex(5);
        enhancement->setTitle("Enhancement");
        enhancement->setType(std::nullopt);
        auto book = new Filter();
        book->setIndex(6);
        book->setTitle("Books");
        book->setType(std::nullopt);
        auto crafting = new Filter();
        crafting->setIndex(7);
        crafting->setTitle("Craft Items");
        crafting->setType(std::nullopt);

        Filters.push_back(all);
        Filters.push_back(weapon);
        Filters.push_back(drapery);
        Filters.push_back(accessory);
        Filters.push_back(consumable);
        Filters.push_back(enhancement);
        Filters.push_back(book);
        Filters.push_back(crafting);

        Filter *tempVar = new Filter();
        tempVar->setIndex(201);
        tempVar->setTitle("Armour");
        tempVar->setType(std::make_optional(ItemType::Armour));
        drapery->SubFilters.push_back(tempVar);
        Filter *tempVar2 = new Filter();
        tempVar2->setIndex(202);
        tempVar2->setTitle("Helmet");
        tempVar2->setType(std::make_optional(ItemType::Helmet));
        drapery->SubFilters.push_back(tempVar2);
        Filter *tempVar3 = new Filter();
        tempVar3->setIndex(203);
        tempVar3->setTitle("Belt");
        tempVar3->setType(std::make_optional(ItemType::Belt));
        drapery->SubFilters.push_back(tempVar3);
        Filter *tempVar4 = new Filter();
        tempVar4->setIndex(204);
        tempVar4->setTitle("Boots");
        tempVar4->setType(std::make_optional(ItemType::Boots));
        drapery->SubFilters.push_back(tempVar4);
        Filter *tempVar5 = new Filter();
        tempVar5->setIndex(205);
        tempVar5->setTitle("Stone");
        tempVar5->setType(std::make_optional(ItemType::Stone));
        drapery->SubFilters.push_back(tempVar5);

        Filter *tempVar6 = new Filter();
        tempVar6->setIndex(301);
        tempVar6->setTitle("Necklaces");
        tempVar6->setType(std::make_optional(ItemType::Necklace));
        accessory->SubFilters.push_back(tempVar6);
        Filter *tempVar7 = new Filter();
        tempVar7->setIndex(302);
        tempVar7->setTitle("Bracelets");
        tempVar7->setType(std::make_optional(ItemType::Bracelet));
        accessory->SubFilters.push_back(tempVar7);
        Filter *tempVar8 = new Filter();
        tempVar8->setIndex(303);
        tempVar8->setTitle("Rings");
        tempVar8->setType(std::make_optional(ItemType::Ring));
        accessory->SubFilters.push_back(tempVar8);

        Filter *tempVar9 = new Filter();
        tempVar9->setIndex(401);
        tempVar9->setTitle("Recovery Pots");
        tempVar9->setType(std::make_optional(ItemType::Potion));
        tempVar9->setMaxShape(2);
        consumable->SubFilters.push_back(tempVar9);
        Filter *tempVar10 = new Filter();
        tempVar10->setIndex(402);
        tempVar10->setTitle("Buff Pots");
        tempVar10->setType(std::make_optional(ItemType::Potion));
        tempVar10->setMinShape(3);
        tempVar10->setMaxShape(4);
        consumable->SubFilters.push_back(tempVar10);
        Filter *tempVar11 = new Filter();
        tempVar11->setIndex(403);
        tempVar11->setTitle("Scrolls / Oils");
        tempVar11->setType(std::make_optional(ItemType::Scroll));
        consumable->SubFilters.push_back(tempVar11);
        Filter *tempVar12 = new Filter();
        tempVar12->setIndex(404);
        tempVar12->setTitle("Misc Items");
        tempVar12->setType(std::make_optional(ItemType::Script));
        consumable->SubFilters.push_back(tempVar12);

        Filter *tempVar13 = new Filter();
        tempVar13->setIndex(501);
        tempVar13->setTitle("Gems");
        tempVar13->setType(std::make_optional(ItemType::Potion));
        tempVar13->setMinShape(3);
        tempVar13->setMaxShape(3);
        enhancement->SubFilters.push_back(tempVar13);
        Filter *tempVar14 = new Filter();
        tempVar14->setIndex(502);
        tempVar14->setTitle("Orbs");
        tempVar14->setType(std::make_optional(ItemType::Potion));
        tempVar14->setMinShape(4);
        tempVar14->setMaxShape(4);
        enhancement->SubFilters.push_back(tempVar14);

        Filter *tempVar15 = new Filter();
        tempVar15->setIndex(601);
        tempVar15->setTitle("Warrior");
        tempVar15->setType(std::make_optional(ItemType::Book));
        tempVar15->setMaxShape(30);
        book->SubFilters.push_back(tempVar15);
        Filter *tempVar16 = new Filter();
        tempVar16->setIndex(602);
        tempVar16->setTitle("Wizard");
        tempVar16->setType(std::make_optional(ItemType::Book));
        tempVar16->setMinShape(31);
        tempVar16->setMaxShape(60);
        book->SubFilters.push_back(tempVar16);
        Filter *tempVar17 = new Filter();
        tempVar17->setIndex(603);
        tempVar17->setTitle("Taoist");
        tempVar17->setType(std::make_optional(ItemType::Book));
        tempVar17->setMinShape(61);
        tempVar17->setMaxShape(90);
        book->SubFilters.push_back(tempVar17);
        Filter *tempVar18 = new Filter();
        tempVar18->setIndex(604);
        tempVar18->setTitle("Assassin");
        tempVar18->setType(std::make_optional(ItemType::Book));
        tempVar18->setMinShape(91);
        tempVar18->setMaxShape(120);
        book->SubFilters.push_back(tempVar18);
        Filter *tempVar19 = new Filter();
        tempVar19->setIndex(605);
        tempVar19->setTitle("Archer");
        tempVar19->setType(std::make_optional(ItemType::Book));
        tempVar19->setMinShape(121);
        tempVar19->setMaxShape(150);
        book->SubFilters.push_back(tempVar19);

        Filter *tempVar20 = new Filter();
        tempVar20->setIndex(701);
        tempVar20->setTitle("Materials");
        tempVar20->setType(std::make_optional(ItemType::CraftingMaterial));
        crafting->SubFilters.push_back(tempVar20);
        Filter *tempVar21 = new Filter();
        tempVar21->setIndex(703);
        tempVar21->setTitle("Meat");
        tempVar21->setType(std::make_optional(ItemType::Meat));
        crafting->SubFilters.push_back(tempVar21);
        Filter *tempVar22 = new Filter();
        tempVar22->setIndex(704);
        tempVar22->setTitle("Ore");
        tempVar22->setType(std::make_optional(ItemType::Ore));
        crafting->SubFilters.push_back(tempVar22);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar22' statement was not added since tempVar22 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar21' statement was not added since tempVar21 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar20' statement was not added since tempVar20 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar19' statement was not added since tempVar19 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar18' statement was not added since tempVar18 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar17' statement was not added since tempVar17 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar16' statement was not added since tempVar16 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar15' statement was not added since tempVar15 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar14' statement was not added since tempVar14 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar13' statement was not added since tempVar13 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar12' statement was not added since tempVar12 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar11' statement was not added since tempVar11 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar10' statement was not added since tempVar10 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar9' statement was not added since tempVar9 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar8' statement was not added since tempVar8 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar7' statement was not added since tempVar7 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar6' statement was not added since tempVar6 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar5' statement was not added since tempVar5 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar4' statement was not added since tempVar4 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar3' statement was not added since tempVar3 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar2' statement was not added since tempVar2 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete crafting' statement was not added since crafting was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete book' statement was not added since book was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete enhancement' statement was not added since enhancement was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete consumable' statement was not added since consumable was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete accessory' statement was not added since accessory was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete drapery' statement was not added since drapery was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete weapon' statement was not added since weapon was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete all' statement was not added since all was passed to a method or constructor. Handle memory management manually.
    }

    void TrustMerchantDialog::DrawFilters(int index, int subIndex)
    {
        SelectedIndex = index;
        SelectedSubIndex = subIndex;

        int btnx = 7;
        int btny = 60;

        int current = 0;
        int skipped = Skip;

        //Dispose all buttons and labels
        for (auto item : FilterButtons)
        {
            item->Dispose();
        }

        for (auto item : FilterLabels)
        {
            item->Dispose();
        }

        FilterButtons.clear();
        FilterLabels.clear();

        PossibleTotal = Filters.size();

        for (auto item : Filters)
        {
            if (skipped > 0)
            {
                skipped--;
                continue;
            }

            if (current >= MaxLines)
            {
                break;
            }

            current++;

            auto btn = new MirButton();
            btn->setIndex(920);
            btn->setPressedIndex(921);
            btn->setHoverIndex(921);
            btn->setLibrary(Libraries::Prguse2);
            btn->setSound(SoundList::ButtonA);
            Point tempVar(btnx, btny);
            btn->setLocation(&tempVar);
            btn->setParent(this);
            btn->Click += [&] (o, e)
            {
                if (item->SubFilters.Any())
                {
                    DrawFilters(item->getIndex(), -1);
                }
                else
                {
                    DrawFilters(item->getIndex(), -1);
    
                    if (item->getType())
                    {
                        C::MarketSearch *tempVar2 = new C::MarketSearch();
                        tempVar2->Match = SearchTextBox->getText();
                        tempVar2->Type = item->getType().value();
                        tempVar2->Usermode = false;
                        tempVar2->MinShape = item->getMinShape();
                        tempVar2->MaxShape = item->getMaxShape();
                        tempVar2->MarketType = MarketType;
                        Network::Enqueue(tempVar2);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar2' statement was not added since tempVar2 was passed to a method or constructor. Handle memory management manually.
                    }
                }
            };

            auto lbl = new MirLabel();
            Size tempVar3(99, 18);
            lbl->setSize(&tempVar3);
            Point tempVar4(2, 1);
            lbl->setLocation(&tempVar4);
            lbl->setParent(btn);
            lbl->setText(item->getTitle());
            lbl->setNotControl(true);

            btny += 20;

            FilterButtons.push_back(btn);
            FilterLabels.push_back(lbl);


            if (item->getIndex() == index)
            {
                PossibleTotal += item->SubFilters.size();

                btn->setIndex(921);

                //btny += 2;

                if (item->SubFilters.Any())
                {
                    btny += 2;
                }

                for (auto subItem : *item->SubFilters)
                {
                    if (skipped > 0)
                    {
                        skipped--;
                        continue;
                    }

                    if (current >= MaxLines)
                    {
                        break;
                    }

                    current++;

                    auto subBtn = new MirButton();
                    subBtn->setIndex(922);
                    subBtn->setPressedIndex(923);
                    subBtn->setHoverIndex(923);
                    subBtn->setLibrary(Libraries::Prguse2);
                    subBtn->setSound(SoundList::ButtonA);
                    Point tempVar5(btnx, btny);
                    subBtn->setLocation(&tempVar5);
                    subBtn->setParent(this);
                    subBtn->Click += [&] (o, e)
                    {
                        DrawFilters(item->getIndex(), subItem->getIndex());
    
                        if (subItem->getType())
                        {
                            C::MarketSearch *tempVar6 = new C::MarketSearch();
                            tempVar6->Match = SearchTextBox->getText();
                            tempVar6->Type = subItem->getType().value();
                            tempVar6->Usermode = false;
                            tempVar6->MinShape = subItem->getMinShape();
                            tempVar6->MaxShape = subItem->getMaxShape();
                            tempVar6->MarketType = MarketType;
                            Network::Enqueue(tempVar6);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar6' statement was not added since tempVar6 was passed to a method or constructor. Handle memory management manually.
                        }
                    };


                    auto sublbl = new MirLabel();
                    Size tempVar7(99, 18);
                    sublbl->setSize(&tempVar7);
                    Point tempVar8(10, 1);
                    sublbl->setLocation(&tempVar8);
                    sublbl->setParent(subBtn);
                    sublbl->setText(subItem->getTitle());
                    sublbl->setNotControl(true);

                    if (subItem->getIndex() == subIndex)
                    {
                        subBtn->setIndex(923);
                    }

                    FilterButtons.push_back(subBtn);
                    FilterLabels.push_back(sublbl);

                    btny += 21;

//C# TO C++ CONVERTER TODO TASK: A 'delete sublbl' statement was not added since sublbl was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete subBtn' statement was not added since subBtn was assigned to another object. Handle memory management manually.
                }
            }

//C# TO C++ CONVERTER TODO TASK: A 'delete lbl' statement was not added since lbl was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete btn' statement was not added since btn was assigned to another object. Handle memory management manually.
        }

        UpdatePositionBar();
    }

    void TrustMerchantDialog::PositionBar_OnMoving(std::any sender, MouseEventArgs *e)
    {
        int x = PosX;
        int y = PositionBar->getLocation()->Y;

        if (y >= PosMaxY)
        {
            y = PosMaxY;
        }
        if (y <= PosMinY)
        {
            y = PosMinY;
        }

        int location = y - PosMinY;
        int interval = (PosMaxY - PosMinY) / (PossibleTotal - MaxLines);

        double yPoint = static_cast<double>(location) / interval;

        Skip = static_cast<short>(std::floor(yPoint));

        Point tempVar(x, y);
        PositionBar->setLocation(&tempVar);

        DrawFilters(SelectedIndex, SelectedSubIndex);
    }

    void TrustMerchantDialog::UpdatePositionBar()
    {
        if (PossibleTotal <= MaxLines)
        {
            PositionBar->setVisible(false);
            return;
        }

        PositionBar->setVisible(true);

        int interval = (PosMaxY - PosMinY) / (PossibleTotal - MaxLines);

        int x = PosX;
        int y = PosMinY + (Skip * interval);

        if (y >= PosMaxY)
        {
            y = PosMaxY;
        }
        if (y <= PosMinY)
        {
            y = PosMinY;
        }


        Point tempVar(x, y);
        PositionBar->setLocation(&tempVar);
    }

    void TrustMerchantDialog::UpdateInterface()
    {
        PageLabel->setText(StringHelper::formatSimple("{0}/{1}", Page + 1, PageCount));
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
        TotalGold->setText(MarketType == MarketPanelType::GameShop ? GameScene::Credit.ToString("###,###,##0") : GameScene::Gold.ToString("###,###,##0"));

        for (int i = 0; i < 10; i++)
        {
            if (i + Page * 10 >= Listings.size())
            {
                Rows[i]->Clear();
                if (Rows[i] == Selected)
                {
                    Selected = nullptr;
                }
            }
            else
            {
                if (Rows[i] == Selected && Selected->Listing != Listings[i + Page * 10])
                {
                    Selected->setBorder(false);
                    Selected = nullptr;
                }

                Rows[i]->Update(Listings[i + Page * 10]);
            }
        }

        for (int i = 0; i < Rows.size(); i++)
        {
            Rows[i]->setBorder(Rows[i] == Selected);
        }

        if (Selected != nullptr)
        {
            BuyButton->setEnabled(true);
            BuyButton->setGrayScale(false);
            MailButton->setEnabled(true);
            MailButton->setGrayScale(false);
        }
        else
        {
            BuyButton->setEnabled(false);
            BuyButton->setGrayScale(true);
            MailButton->setEnabled(false);
            MailButton->setGrayScale(true);
        }

        if (Selected != nullptr && Selected->Listing->Seller == "Bid Met")
        {
            SellNowButton->setEnabled(true);
            SellNowButton->setGrayScale(false);
        }
        else
        {
            SellNowButton->setEnabled(false);
            SellNowButton->setGrayScale(true);
        }
    }

    void TrustMerchantDialog::SearchTextBox_KeyPress(std::any sender, KeyPressEventArgs *e)
    {
        if (CMain::Time < SearchTime)
        {
            GameScene::Scene->ChatDialog->ReceiveChat(StringHelper::formatSimple("You can search again after {0} seconds.", std::ceil((SearchTime - CMain::Time) / 1000)), ChatType::System);
            return;
        }

        switch (e->KeyChar)
        {
            case static_cast<char>(Keys->Enter):
                e->Handled = true;
                if (SearchTextBox->getText().empty())
                {
                    return;
                }
                SearchTime = CMain::Time + Globals::SearchDelay;
                C::MarketSearch *tempVar = new C::MarketSearch();
                tempVar->Match = SearchTextBox->getText();
                tempVar->MarketType = MarketType;
                Network::Enqueue(tempVar);
                Program::Form->ActiveControl = nullptr;
                break;
            case static_cast<char>(Keys->Escape):
                e->Handled = true;
                break;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
        }
    }

    void TrustMerchantDialog::SearchTextBox_KeyUp(std::any sender, KeyEventArgs *e)
    {
        CMain::Shift = e->Shift;
        CMain::Alt = e->Alt;
        CMain::Ctrl = e->Control;

        switch (e->KeyCode)
        {
            case Keys->F1:
            case Keys->F2:
            case Keys->F3:
            case Keys->F4:
            case Keys->F5:
            case Keys->F6:
            case Keys->F7:
            case Keys->F8:
            case Keys->F9:
            case Keys->F10:
            case Keys->F11:
            case Keys->F12:
            case Keys->Tab:
            case Keys->Escape:
                CMain::CMain_KeyUp(sender, e);
                break;

        }
    }

    void TrustMerchantDialog::SearchTextBox_KeyDown(std::any sender, KeyEventArgs *e)
    {
        CMain::Shift = e->Shift;
        CMain::Alt = e->Alt;
        CMain::Ctrl = e->Control;

        switch (e->KeyCode)
        {
            case Keys->F1:
            case Keys->F2:
            case Keys->F3:
            case Keys->F4:
            case Keys->F5:
            case Keys->F6:
            case Keys->F7:
            case Keys->F8:
            case Keys->F9:
            case Keys->F10:
            case Keys->F11:
            case Keys->F12:
            case Keys->Tab:
            case Keys->Escape:
                CMain::CMain_KeyDown(sender, e);
                break;

        }
    }

    void TrustMerchantDialog::TMerchantDialog(MarketPanelType type)
    {
        MarketButton->setIndex(789);
        ConsignmentButton->setIndex(791);
        AuctionButton->setIndex(817);
        GameShopButton->setIndex(819);

        switch (type)
        {
            case MarketPanelType::Market:
                setIndex(786);
                MarketButton->setIndex(788);
                BuyButton->setIndex(703);
                BuyButton->setHoverIndex(704);
                BuyButton->setPressedIndex(705);
                SellNowButton->setVisible(false);
                UpButton->setVisible(true);
                DownButton->setVisible(true);
                PositionBar->setVisible(true);
                DrawFilters(0, -1);

                TitleSalePriceLabel->setVisible(false);
                TitleSellLabel->setVisible(false);
                TitleItemLabel->setVisible(true);
                TitlePriceLabel->setVisible(true);
                TitleExpiryLabel->setVisible(true);
                TitleSalePriceLabel->setText("SALE PRICE");
                TitleSellLabel->setText("SELL ITEM");
                TitleItemLabel->setText("ITEM");
                TitlePriceLabel->setText("PRICE / BID");
                TitleExpiryLabel->setText("SELLER / EXPIRY");

                //TotalGold.Visible = true;
                PriceTextBox->setVisible(false);
                ItemCell->setVisible(false);
                MailButton->setVisible(true);
                FindButton->setVisible(true);
                SellItemButton->setVisible(false);
                SearchTextBox->setVisible(true);
                RefreshButton->setVisible(true);
                HelpLabel->setVisible(false);
                MarketType = MarketPanelType::Market;
                C::MarketSearch *tempVar = new C::MarketSearch();
                tempVar->Match = "";
                tempVar->Type = ItemType::Nothing;
                tempVar->Usermode = false;
                tempVar->MarketType = MarketType;
                Network::Enqueue(tempVar);
                break;
            case MarketPanelType::Consign:
                setIndex(787);
                ConsignmentButton->setIndex(790);

                MailButton->setVisible(false);
                BuyButton->setIndex(706);
                BuyButton->setHoverIndex(707);
                BuyButton->setPressedIndex(708);
                SellNowButton->setVisible(false);
                UpButton->setVisible(false);
                DownButton->setVisible(false);
                PositionBar->setVisible(false);
                //TotalGold.Visible = false;
                PriceTextBox->setVisible(true);
                PriceTextBox->setText("");
                ItemCell->setVisible(true);
                SellItemButton->setVisible(true);
                SellItemButton->setEnabled(false);
                FindButton->setVisible(false);
                SearchTextBox->setVisible(false);
                RefreshButton->setVisible(false);
                HelpLabel->setVisible(true);
                HelpLabel->setText(consignmentText);

                TitleSalePriceLabel->setVisible(true);
                TitleSellLabel->setVisible(true);
                TitleItemLabel->setVisible(true);
                TitlePriceLabel->setVisible(true);
                TitleExpiryLabel->setVisible(true);
                TitleSalePriceLabel->setText("SALE PRICE");
                TitleSellLabel->setText("SELL ITEM");
                TitleItemLabel->setText("ITEM");
                TitlePriceLabel->setText("PRICE");
                TitleExpiryLabel->setText("EXPIRY");

                for (auto item : FilterButtons)
                {
                    item->setVisible(false);
                }

                MarketType = MarketPanelType::Consign;
                C::MarketSearch *tempVar2 = new C::MarketSearch();
                tempVar2->Match = "";
                tempVar2->Type = ItemType::Nothing;
                tempVar2->Usermode = true;
                tempVar2->MarketType = MarketType;
                Network::Enqueue(tempVar2);
                break;
            case MarketPanelType::Auction:
                setIndex(787);
                AuctionButton->setIndex(816);

                MailButton->setVisible(false);
                BuyButton->setIndex(706);
                BuyButton->setHoverIndex(707);
                BuyButton->setPressedIndex(708);
                SellNowButton->setVisible(true);
                UpButton->setVisible(false);
                DownButton->setVisible(false);
                PositionBar->setVisible(false);
                //TotalGold.Visible = false;
                PriceTextBox->setVisible(true);
                PriceTextBox->setText("");
                ItemCell->setVisible(true);
                SellItemButton->setVisible(true);
                SellItemButton->setEnabled(false);
                FindButton->setVisible(false);
                SearchTextBox->setVisible(false);
                RefreshButton->setVisible(false);
                HelpLabel->setVisible(true);
                HelpLabel->setText(auctionText);

                TitleSalePriceLabel->setVisible(true);
                TitleSellLabel->setVisible(true);
                TitleItemLabel->setVisible(true);
                TitlePriceLabel->setVisible(true);
                TitleExpiryLabel->setVisible(true);
                TitleSalePriceLabel->setText("STARTING BID");
                TitleSellLabel->setText("SELL ITEM");
                TitleItemLabel->setText("ITEM");
                TitlePriceLabel->setText("HIGHEST BID");
                TitleExpiryLabel->setText("END DATE");

                for (auto item : FilterButtons)
                {
                    item->setVisible(false);
                }

                MarketType = MarketPanelType::Auction;
                C::MarketSearch *tempVar3 = new C::MarketSearch();
                tempVar3->Match = "";
                tempVar3->Type = ItemType::Nothing;
                tempVar3->Usermode = true;
                tempVar3->MarketType = MarketType;
                Network::Enqueue(tempVar3);
                break;
            case MarketPanelType::GameShop:
                setIndex(786);
                GameShopButton->setIndex(818);

                BuyButton->setIndex(703);
                BuyButton->setHoverIndex(704);
                BuyButton->setPressedIndex(705);
                SellNowButton->setVisible(false);
                UpButton->setVisible(true);
                DownButton->setVisible(true);
                PositionBar->setVisible(true);
                DrawFilters(0, -1);
                //TotalGold.Visible = true;
                PriceTextBox->setVisible(false);
                ItemCell->setVisible(false);
                MailButton->setVisible(false);
                FindButton->setVisible(true);
                SellItemButton->setVisible(false);
                SearchTextBox->setVisible(true);
                RefreshButton->setVisible(false);
                HelpLabel->setVisible(false);

                TitleSalePriceLabel->setVisible(false);
                TitleSellLabel->setVisible(false);
                TitleItemLabel->setVisible(true);
                TitlePriceLabel->setVisible(true);
                TitleExpiryLabel->setVisible(true);
                TitleSalePriceLabel->setText("SALE PRICE");
                TitleSellLabel->setText("SELL ITEM");
                TitleItemLabel->setText("ITEM");
                TitlePriceLabel->setText("PRICE");
                TitleExpiryLabel->setText("");

                MarketType = MarketPanelType::GameShop;
                C::MarketSearch *tempVar4 = new C::MarketSearch();
                tempVar4->Match = "";
                tempVar4->Type = ItemType::Nothing;
                tempVar4->Usermode = false;
                tempVar4->MarketType = MarketType;
                Network::Enqueue(tempVar4);
                break;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar4' statement was not added since tempVar4 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar3' statement was not added since tempVar3 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar2' statement was not added since tempVar2 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
        }

        UpdateInterface();
    }

    void TrustMerchantDialog::TextBox_TextChanged(std::any sender, EventArgs *e)
    {
        if (MarketType == MarketPanelType::Consign)
        {
            if (unsigned int::TryParse(PriceTextBox->getText(), Amount) && Amount >= MinConsignAmount)
            {
                PriceTextBox->setBorderColour(Color::Lime);

                if (Amount > MaxConsignAmount)
                {
                    Amount = MaxConsignAmount;
                    PriceTextBox->setText(std::to_string(MaxConsignAmount));
                    PriceTextBox->TextBox->SelectionStart = PriceTextBox->getText().length();
                    SellItemButton->setEnabled(true);
                }

                if (Amount == MaxConsignAmount)
                {
                    PriceTextBox->setBorderColour(Color::Orange);
                }
                SellItemButton->setEnabled(true);
            }
            else
            {
                PriceTextBox->setBorderColour(Color::Red);
                SellItemButton->setEnabled(false);
            }
        }
        else if (MarketType == MarketPanelType::Auction)
        {
            if (unsigned int::TryParse(PriceTextBox->getText(), Amount) && Amount >= MinBidAmount)
            {
                PriceTextBox->setBorderColour(Color::Lime);

                if (Amount > MaxBidAmount)
                {
                    Amount = MaxBidAmount;
                    PriceTextBox->setText(std::to_string(MaxBidAmount));
                    PriceTextBox->TextBox->SelectionStart = PriceTextBox->getText().length();
                    SellItemButton->setEnabled(true);
                }

                if (Amount == MaxBidAmount)
                {
                    PriceTextBox->setBorderColour(Color::Orange);
                }
                SellItemButton->setEnabled(true);
            }
            else
            {
                PriceTextBox->setBorderColour(Color::Red);
                SellItemButton->setEnabled(false);
            }
        }
    }

    void TrustMerchantDialog::MirInputBox_KeyPress(std::any sender, KeyPressEventArgs *e)
    {
        if (!std::iscntrl(e->KeyChar) && !std::isdigit(e->KeyChar))
        {
            e->Handled = true;
        }
    }

    void TrustMerchantDialog::ItemCell_Click()
    {
        if (tempCell != nullptr)
        {
            tempCell->setLocked(false);
            SellItemSlot = nullptr;
            tempCell = nullptr;
        }

        if (GameScene::SelectedCell == nullptr || GameScene::SelectedCell->getGridType() != MirGridType::Inventory || GameScene::SelectedCell->getItem() != nullptr && GameScene::SelectedCell->getItem()->Info->Durability < 0)
        {
            return;
        }

        SellItemSlot = GameScene::SelectedCell->getItem();
        tempCell = GameScene::SelectedCell;
        tempCell->setLocked(true);
        GameScene::SelectedCell = nullptr;
        PriceTextBox->SetFocus();
    }

    void TrustMerchantDialog::Hide()
    {
        if (!getVisible())
        {
            return;
        }
        setVisible(false);

        Listings.clear();

        if (tempCell != nullptr)
        {
            tempCell->setLocked(false);
            SellItemSlot = nullptr;
            tempCell = nullptr;
        }
    }

    void TrustMerchantDialog::Show(bool gameshop)
    {
        if (getVisible())
        {
            return;
        }
        setVisible(true);

        if (gameshop)
        {
            MarketButton->setVisible(false);
            ConsignmentButton->setVisible(false);
            AuctionButton->setVisible(false);
            GameShopButton->setVisible(true);
            TMerchantDialog(MarketPanelType::GameShop);
        }
        else
        {
            MarketButton->setVisible(true);
            ConsignmentButton->setVisible(true);
            AuctionButton->setVisible(true);
            GameShopButton->setVisible(false);
            TMerchantDialog(MarketPanelType::Market);
        }
    }

    TrustMerchantDialog::AuctionRow::AuctionRow()
    {
        Size tempVar(354, 32);
        setSize(&tempVar);
        setSound(SoundList::ButtonA);
        setBorderColour(Color::FromArgb(255, 200, 100, 0));
        BeforeDraw += AuctionRow_BeforeDraw;

        NameLabel = new MirLabel();
        NameLabel->setAutoSize(true);
        Size tempVar2(140, 20);
        NameLabel->setSize(&tempVar2);
        Point tempVar3(38, 8);
        NameLabel->setLocation(&tempVar3);
        NameLabel->setDrawFormat(TextFormatFlags::HorizontalCenter | TextFormatFlags::VerticalCenter);
        NameLabel->setNotControl(true);
        NameLabel->setParent(this);

        PriceLabel = new MirLabel();
        PriceLabel->setAutoSize(true);
        Size tempVar4(178, 20);
        PriceLabel->setSize(&tempVar4);
        Point tempVar5(170, 8);
        PriceLabel->setLocation(&tempVar5);
        PriceLabel->setDrawFormat(TextFormatFlags::HorizontalCenter | TextFormatFlags::VerticalCenter);
        PriceLabel->setNotControl(true);
        PriceLabel->setParent(this);

        SellerLabel = new MirLabel();
        SellerLabel->setAutoSize(true);
        Size tempVar6(148, 20);
        SellerLabel->setSize(&tempVar6);
        Point tempVar7(256, 0);
        SellerLabel->setLocation(&tempVar7);
        SellerLabel->setDrawFormat(TextFormatFlags::HorizontalCenter | TextFormatFlags::VerticalCenter);
        SellerLabel->setNotControl(true);
        SellerLabel->setParent(this);

        IconImage = new MirImageControl();
        IconImage->setIndex(0);
        IconImage->setLibrary(Libraries::Prguse);
        Point tempVar8(0, 0);
        IconImage->setLocation(&tempVar8);
        IconImage->setParent(this);


        SelectedImage = new MirImageControl();
        SelectedImage->setIndex(545);
        SelectedImage->setLibrary(Libraries::Prguse);
        Point tempVar9(-5, -3);
        SelectedImage->setLocation(&tempVar9);
        SelectedImage->setParent(this);
        SelectedImage->setVisible(false);
        SelectedImage->setNotControl(true);

        ExpireLabel = new MirLabel();
        ExpireLabel->setAutoSize(true);
        Point tempVar10(256, 14);
        ExpireLabel->setLocation(&tempVar10);
        Size tempVar11(110, 22);
        ExpireLabel->setSize(&tempVar11);
        ExpireLabel->setDrawFormat(TextFormatFlags->Left | TextFormatFlags::VerticalCenter);
        ExpireLabel->setParent(this);
        ExpireLabel->setNotControl(true);

        UpdateInterface();
    }

    void TrustMerchantDialog::AuctionRow::AuctionRow_BeforeDraw(std::any sender, EventArgs *e)
    {
        UpdateInterface();
    }

    void TrustMerchantDialog::AuctionRow::UpdateInterface()
    {
        if (Listing == nullptr)
        {
            return;
        }

        IconImage->setVisible(true);

        if (Listing->Item->Count > 0)
        {
            IconImage->setIndex(Listing->Item->Info->Image);
            IconImage->setLibrary(Libraries::Items);
        }
        else
        {
            IconImage->setIndex(540);
            IconImage->setLibrary(Libraries::Prguse);
        }

        Point tempVar((IconArea->Width - IconImage->getSize()->Width) / 2, (IconArea->Height - IconImage->getSize()->Height) / 2);
        IconImage->setLocation(&tempVar);

        SellerLabel->setVisible(Listing->ItemType == MarketItemType::Consign || Listing->ItemType == MarketItemType::Auction);
        ExpireLabel->setVisible(Listing != nullptr && (Listing->ItemType == MarketItemType::Consign || Listing->ItemType == MarketItemType::Auction));

        if (Listing == nullptr)
        {
            return;
        }

        ExpireLabel->setText(std::string::Format("{0:dd/MM/yy HH:mm:ss}", Listing->ConsignmentDate.AddDays(Globals::ConsignmentLength)));
    }

    void TrustMerchantDialog::AuctionRow::Dispose(bool disposing)
    {
        MirControl::Dispose(disposing);

        SelectedImage = nullptr;
        IconImage = nullptr;

        Selected = false;
    }

    void TrustMerchantDialog::AuctionRow::Clear()
    {
        setVisible(false);
        NameLabel->setText("");
        PriceLabel->setText("");
        SellerLabel->setText("");
    }

    void TrustMerchantDialog::AuctionRow::Update(ClientAuction *listing)
    {
        Listing = listing;
        NameLabel->setText(Listing->Item->getFriendlyName());
        PriceLabel->setText(std::string::Format("{0:###,###,##0} {1}", Listing->Price, listing->ItemType == MarketItemType::Auction ? "Bid" : ""));

        NameLabel->setForeColour(GameScene::Scene->GradeNameColor(Listing->Item->Info->Grade));
        if (NameLabel->getForeColour() == Color::Yellow)
        {
            NameLabel->setForeColour(Color::White);
        }

        if (Listing->Price > 10000000) //10Mil
        {
            PriceLabel->setForeColour(Color::Red);
        }
        else if (listing->Price > 1000000) //1Million
        {
            PriceLabel->setForeColour(Color::Orange);
        }
        else if (listing->Price > 100000) //1Million
        {
            PriceLabel->setForeColour(Color::LawnGreen);
        }
        else if (listing->Price > 10000) //1Million
        {
            PriceLabel->setForeColour(Color::DeepSkyBlue);
        }
        else
        {
            PriceLabel->setForeColour(Color::White);
        }


        SellerLabel->setText(Listing->Seller);
        SellerLabel->setForeColour(Color::White);

        if (UserMode)
        {
//C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic:
//            switch (Listing.Seller)
//ORIGINAL LINE: case "Sold":
            if (Listing->Seller == "Sold")
            {
                    SellerLabel->setForeColour(Color::Gold);
            }
//ORIGINAL LINE: case "Expired":
            else if (Listing->Seller == "Expired")
            {
                    SellerLabel->setForeColour(Color::Red);
            }
//ORIGINAL LINE: case "Bid Met":
            else if (Listing->Seller == "Bid Met")
            {
                    SellerLabel->setForeColour(Color::LawnGreen);
            }
            else
            {
                    SellerLabel->setForeColour(Color::White);
            }
        }
        setVisible(true);
    }

    void TrustMerchantDialog::AuctionRow::OnMouseEnter()
    {
        if (Listing == nullptr)
        {
            return;
        }

        MirControl::OnMouseEnter();
        GameScene::Scene->CreateItemLabel(Listing->Item);
    }

    void TrustMerchantDialog::AuctionRow::OnMouseLeave()
    {
        if (Listing == nullptr)
        {
            return;
        }

        MirControl::OnMouseLeave();
        GameScene::Scene->DisposeItemLabel();
        GameScene::HoverItem = nullptr;
    }

    int TrustMerchantDialog::Filter::getIndex() const
    {
        return Index;
    }

    void TrustMerchantDialog::Filter::setIndex(int value)
    {
        Index = value;
    }

    std::string TrustMerchantDialog::Filter::getTitle() const
    {
        return Title;
    }

    void TrustMerchantDialog::Filter::setTitle(const std::string &value)
    {
        Title = value;
    }

    std::optional<ItemType> TrustMerchantDialog::Filter::getType() const
    {
        return Type;
    }

    void TrustMerchantDialog::Filter::setType(const std::optional<ItemType> &value)
    {
        Type = value;
    }

    short TrustMerchantDialog::Filter::getMinShape() const
    {
        return MinShape;
    }

    void TrustMerchantDialog::Filter::setMinShape(short value)
    {
        MinShape = value;
    }

    short TrustMerchantDialog::Filter::getMaxShape() const
    {
        return MaxShape;
    }

    void TrustMerchantDialog::Filter::setMaxShape(short value)
    {
        MaxShape = value;
    }
}
